package com.google.sky.flow;

import com.google.common.collect.Sets;
import com.google.sky.MoveResolver;
import com.google.sky.Position;
import com.google.sky.domain.Mark;
import com.google.sky.domain.MovableBoard;
import com.google.sky.dto.CellState;

import java.util.Set;

/**
 * @author: sk_y
 */
public class MoveControllerImpl implements MoveController {


    private MoveResolver moveResolver;

    private Long lastMoveTime;

    private Long allMovesTime;

    private Mark mark;

    private Set<CellState> cellStates = Sets.newCopyOnWriteArraySet();

    public MoveControllerImpl(Mark mark) {
        this.mark = mark;
    }

    public void setMoveResolver(MoveResolver moveResolver) {
        this.moveResolver = moveResolver;
    }

    @Override
    public void nextMove(MovableBoard board) {
        long startTime = System.currentTimeMillis();
        Position nextPosition =  moveResolver.nextStep(board);
        lastMoveTime = System.currentTimeMillis()-startTime;
        allMovesTime = allMovesTime==null ? lastMoveTime : allMovesTime+lastMoveTime;
        if (nextPosition==null){

        }
        board.makeMove(nextPosition, mark);
    }

    @Override
    public Long getLastMoveTime() {
        return lastMoveTime;
    }

    @Override
    public Long getAllMovesTime() {
        return allMovesTime;
    }

    @Override
    public Mark getMark() {
        return mark;
    }
}
